<template>
  <div style="width: 100% " class="textcolor">
    <h4 class="boardName textcolor" @click="gotoThat">
      报警分析
      <a-icon type="right" />
    </h4>
    <div class="lightBox" style="height: 422px;">
      <!--              环形图-->
      <div class="pieChartsAlarm">
        <pieCharts v-if="pieData.length > 0" :chartData="pieData" :chartColor="colorList" :height="'180px'" />
      </div>
      <div class="AlarmnumBox">
        <div v-for="(item, index) in pieData" :key="index">
          <h5>{{ item.str || 0 }}</h5>
          <p>{{ item.name }}(个)</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import pieCharts from '../../../echartsCom/pieCharts.vue';

let colorList = ['#FF3535', '#FF7865', '#FFBB00', '#f8d77e'];
export default {
  name: 'index',
  components: {
    pieCharts,
  },
  props: {
    AlarmList: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    let moment = this.$Moment;
    return {
      userName: '',
      name: '',
      role: '',
      compId: '',
      dateType: 1,
      pieData: [],
      colorList: colorList,
    };
  },
  watch: {
    AlarmList(val) {
      this.AlarmListIn(val);
    },
  },
  methods: {
    gotoThat() {
      this.$store.commit('board/HeadNavType', 2);
      localStorage.setItem('navType', 2);
      this.$router.push('/statistics');
    },
    AlarmListIn(list) {
      let data = [
        { value: '0', name: '一级报警' },
        { value: '0', name: '二级报警' },
        { value: '0', name: '三级报警' },
        {
          value: '0',
          name: '系统提示信息',
        },
      ];
      list.forEach((item, index) => {
        if (item.alarmType == 1) {
          data[0].value = (item.rate * 100).toFixed(2);
          data[0].str = item.count;
        } else if (item.alarmType == 2) {
          data[1].value = (item.rate * 100).toFixed(2);
          data[1].str = item.count;
        } else if (item.alarmType == 3) {
          data[2].value = (item.rate * 100).toFixed(2);
          data[2].str = item.count;
        } else if (item.alarmType == 4) {
          data[3].value = (item.rate * 100).toFixed(2);
          data[3].str = item.count;
        }
      });
      this.pieData = data;
    },
  },
};
</script>

<style scoped lang="less">
@import '../../light.less';
</style>
